package com.orange.core.pojo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>ClassName:RefundStatus</p>
 * <p>Description: 退款枚举</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/7/14 16:08</p>
 */
@AllArgsConstructor
@Getter
public enum RefundStatus implements Serializable {

    NOT_REFUNDED(0, "未退款"),
    REFUNDED(1, "已退款"),
    REFUNDING(2, "退款中");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String desc;

    private static final Map<Integer,RefundStatus> CODE_TO_MENUM_MAP = Arrays.stream(values())
            .collect(Collectors.toUnmodifiableMap(RefundStatus::getCode, e -> e));

    public static RefundStatus getByCode (Integer code) {
        RefundStatus refundStatus = CODE_TO_MENUM_MAP.get(code);
        if(refundStatus == null) {
            throw new IllegalArgumentException("无效的code值: " + code);
        }
        return refundStatus;
    }
}
